package common

import (
	"encoding/json"
	"io/ioutil"
	"time"
)

//数据库配置信息
type Config struct {
	Ip       string        `json:"ip"`
	Port     string        `json:"port"`
	UserName string        `json:"userName"`
	Password string        `json:"password"`
	DbName   string        `json:"dbName"`
	Cookie   string        `json:"cookie"`
	Rate     time.Duration `json:"rate"`

	Endpoint        string
	AccessKeyId     string
	AccessKeySecret string
	BucketName      string
}

var (
	G_config *Config
)

func InitConfig(filename string) (err error) {
	var (
		content []byte
		conf    Config
	)
	if content, err = ioutil.ReadFile(filename); err != nil {
		return
	}

	if err = json.Unmarshal(content, &conf); err != nil {
		return
	}
	G_config = &conf
	return
}
